Allow defaults in function signatures with syntax (..., p = e, ...).#30
Allow defaults in function signatures with syntax (..., p = e, ...).#30m-kurtenacker wants to merge 21 commits intomasterfrom
Conversation
|
There is a potential issue when the other parameters are bound to the default expression: This code causes the scoping to break, which can be observed by a number of free parameters being found during thorin's internal verification. |
Revert adding DefaultParamType. Instead, use CallExpr::infer. This only works if the parameter and argument lists materialize as tuples. Single parameters are not encapsulated like that and need special treatment later down the line.
|
I changed the way defaults are propagated somewhat. The following example should work: Lines 1190 to 1191 in ed0d2d8 I don't know of any good ways to copy an ast::Node the way it would be required here. The way this is currently implemented generated multiple unique pointers to the same address, leading to undefined behavior. |
This syntax is used elsewhere as well, but very inconsistently. An alternative, at least on Linux/Mac, is to output to /dev/stdout instead.
multiple parameters as defaults.
|
|
||
| T* operator->() const { return _ptr; } | ||
| T& operator*() const { return *_ptr; } | ||
| operator bool() const { return _ptr; } |
There was a problem hiding this comment.
better use
explicit operator bool() const { return _ptr; }This will disallow unintentional casts to bool but
if (ptr) { ... }is allowed!
| other._ptr = _ptr; | ||
| _ptr = tmp; | ||
| } | ||
| }; |
There was a problem hiding this comment.
the correct way to do it is like this:
friend template<class T> void swap(arena_ptr<T>& p, arena_ptr<T>& q) noexcept {
using std::swap;
swap(p.ptr, q.ptr);
}You want to have swap as a free function and make it available via ADL to others using swap. This is also why there is using std::swap: Either use the swap function provided via ADL for p.ptr or use std::swap as fallback,
There was a problem hiding this comment.
is this a correctness issue in the UB sense, or a stylistic issue ? this code is transitional and used only in one place, most likely I'll delete it soon anyhow
There was a problem hiding this comment.
Mostly a stylistic issue. But you want to make sure that - whenever you have another class that aggregates the arena_ptr (such as std::vector<arena_ptr<T>> - the correct swap is invoked. This will not happen if you make swap a member function. But in this particular case it doesn't matter much. So if it's transitional code anyway, no worries ...
This hijacks the implicit summoning to also allow for defaults to be specified. Type checking infers a type for the supplied expression first, and then checks that the parameter matches. As a consequence, the following variants are all valid: